package com.yes_iot.service.impl;

import com.yes_iot.dao.VisualMoudleDao;
import com.yes_iot.dao.VisualMoudleLibraryDao;
import com.yes_iot.entity.VisualMoudleLibrary;
import com.yes_iot.service.VisualMoudleLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
public class VisualMoudleLibraryServiceImpl extends AbstractEntityService implements VisualMoudleLibraryService {
    @Autowired
    private VisualMoudleLibraryDao visualMoudleLibraryDao;
    @Autowired
    private VisualMoudleDao visualMoudleDao;
    @Override
    public List<VisualMoudleLibrary> findVisualMoudelLibraryByDevCode(String devCode) {
        return visualMoudleLibraryDao.findVisualMoudelLibraryByDevCode(devCode);
    }

    @Override
    public List<VisualMoudleLibrary> findVisualMoudelLibraryByVisualDisplayParentId(String parentId) {
        return visualMoudleLibraryDao.findVisualMoudelLibraryByVisualDisplayParentId(UUID.fromString(parentId));
    }

    @Override
    @Transactional
    public void delete(String id) {
        UUID uuid = UUID.fromString(id);
        visualMoudleDao.deleteByVisualMoudleLibraryId(uuid);
        visualMoudleLibraryDao.deleteById(uuid);
    }

    @Override
    public VisualMoudleLibrary save(VisualMoudleLibrary visualMoudleLibrary) {
        return visualMoudleLibraryDao.save(visualMoudleLibrary);
    }
}
